<template>
	<div class="loading" v-if="loadShow">
		<div class="loading-con">
			<img src="@/assets/img/loading.gif" alt="">
			<p>{{tips}}</p>
		</div>
	</div>
</template>
<script>
import * as api from '@/api/index';

export default {
	name: 'home',
	data () {
		return {
            loadShow:true,
			userId: this.$store.state.userId,
            roleList: JSON.parse(localStorage.getItem("rolesList")),            //用户列表
			tips:"正在加载活动信息..."
		}
	},
	created:function() {
		if(!this.userId){
			this.$router.replace({path:'/login'});	
			return false;
		}
		if(this.roleList.length==1) this.getUserInfo()
		else this.$router.replace({path:'/roles'});	
		// this.getUserInfo()
	},
	mounted:function(){
		
	},
	methods:{
		/*****
		 * 获取活动信息
		 * sstUserType: 1教师  2学生
		 * stagesType: 1报名 2初赛 3复赛
		 * ****/ 
		async getUserInfo(){
			var data = {
				userId: this.userId
			}
			var res = await api.getUserInfo(data)
			if(res.resultCode == 1){
				let resVal =  res.value
				localStorage.setItem("userInfo",JSON.stringify(resVal));
				if(resVal.stagesType == 1) this.$router.replace({path:'/signup'});	
				else if(resVal.stagesType == 2) this.$router.replace({path:'/preliminary'});		
				else{
					this.tips = "暂未开始新的阶段..."
				}			
			}else{
				this.$LayerTips({
                    content: res.resultMessage,
                    time: 1500
                });
				this.$router.replace({path:'/login'});	
			}
		},
		
	}
}
</script>
